package com.test.fundible.fundible_00_utils;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.ViewGroup;
import android.widget.TextView;

import com.test.fundible.R;
import com.test.fundible.fundible_00_http.OkHttpUtil;


public class Kind_fundibleTip_fundibleDialog extends Dialog {

    private final String content;
    private final String okBtnText;
    private final Runnable runOnAgree;

    public Kind_fundibleTip_fundibleDialog(
            Context context, String content, String okBtnText, Runnable runOnAgree) {
        super(context);
        this.content = content;
        this.okBtnText = okBtnText;
        this.runOnAgree = runOnAgree;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_fundible_kind_tip);

        getWindow().setBackgroundDrawableResource(R.color.transparent);
        setCanceledOnTouchOutside(true);
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

        initView_fundible();
    }

    @SuppressLint({"SetTextI18n", "ClickableViewAccessibility"})
    private void initView_fundible(){

        TextView contentTv = findViewById(R.id.dfkt_tv_text);
        TextView okBtn = findViewById(R.id.dfkt_btn_ok);

        if (!TextUtils.isEmpty(content)) contentTv.setText(kindtipTest(content));
        if (!TextUtils.isEmpty(okBtnText)) okBtn.setText(kindtipTest(okBtnText));

        okBtn.setOnClickListener(v -> {
            OkHttpUtil.getInstance_fundible().uploadEventPoint("KIND_TIP","OK_CLICK","");
            dismiss();
            if (runOnAgree !=null) runOnAgree.run();
        });

        findViewById(R.id.dfkt_view_out).setOnClickListener(v -> dismiss());

        findViewById(R.id.dfkt_view_in).setOnTouchListener((v, event) -> true);

    }

    private String kindtipTest(String content){
        return content.trim();
    }

    @Override
    public void dismiss() {
        super.dismiss();
        OkHttpUtil.getInstance_fundible().uploadEventPoint("KIND_TIP","CLOSE_CLICK","");
    }

}
